package com.kly.user.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.google.common.collect.Maps;
import com.kly.user.db.dao.UserConversationChatterDao;
import com.kly.user.db.entity.UserConversationChatterEntity;
import com.kly.user.db.entity.UserConversationEntity;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* User: user
* Date: 2024-02-27
* Time: 10:02:53.620
*/

@Repository
public class UserConversationChatterDaoImpl extends AbstractBaseMapper<UserConversationChatterEntity> implements UserConversationChatterDao {

    @Override
    public int doDeleted(String userCode, String userCodeFriend) {
        final HashMap<String, Object> params = Maps.newHashMap();
        params.put("userCode", userCode);
        params.put("userCodeFriend", userCodeFriend);
        return this.getSqlSession().update(this.getStatement("doDeleted"), params);
    }

    @Override
    public int insertConversation(UserConversationEntity userConversationEntity) {
        userConversationEntity.setGmtModified(new Date());
        userConversationEntity.setDeleted(false);
        userConversationEntity.setGmtCreate(new Date());
        this.getSqlSession().insert(this.getStatement(".insertConversation"), userConversationEntity);
        return 0;
    }

    @Override
    public void saveOrUpdate(UserConversationEntity record) {
        this.getSqlSession().insert(this.getStatement("saveOrUpdate"), record);
    }

    @Override
    public List<UserConversationChatterEntity> getUserLastConversationList(Date latestTime) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("latestTime", latestTime);
        return this.getSqlSession().selectList(this.getStatement("getUserLastConversationList"), params);
    }

    @Override
    public List<UserConversationChatterEntity> getConversationByUserCode(String userCode, Date latestTime) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("userCode", userCode);
        params.put("latestTime", latestTime);
        return this.getSqlSession().selectList(this.getStatement("getConversationByUserCode"), params);
    }
}